package z.explorer.ui;

import javax.swing.*;
import java.awt.*;

import z.explorer.ui.component.*;
import z.explorer.ui.component.marker.ZMarker;
import z.explorer.ui.component.menu.ZMenuBar;
import z.explorer.ui.component.navigator.ZNavigator;
import z.explorer.ui.component.statusbar.ZStatusBar;
import z.explorer.ui.component.toolbar.ZToolBar;
import z.explorer.ui.component.walker.ZWalker;

public class Explorer extends JFrame {
	private static final long serialVersionUID = 5348911085393265846L;

	private ZMenuBar zMenuBar =null;// new ZMenuBar();
	private ZToolBar zToolBar =null; //new ZToolBar();
	private ZNavigator zNavigator = null;// new ZNavigator();
	private ZWalker zWalker =null;// new ZWalker();
	private ZMarker zMarker = null;//new ZMarker();
	private ZStatusBar zStatusBar =null;// new ZStatusBar();

	public Explorer() {
		
	}
	
	public void init(){
		setJMenuBar(zMenuBar);
		fillContent();
		configureLocation();
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setVisible(true);
	}
	
	public ZMenuBar getzMenuBar() {
		return zMenuBar;
	}

	public void setzMenuBar(ZMenuBar zMenuBar) {
		this.zMenuBar = zMenuBar;
	}

	public ZToolBar getzToolBar() {
		return zToolBar;
	}

	public void setzToolBar(ZToolBar zToolBar) {
		this.zToolBar = zToolBar;
	}

	public ZNavigator getzNavigator() {
		return zNavigator;
	}

	public void setzNavigator(ZNavigator zNavigator) {
		this.zNavigator = zNavigator;
	}

	public ZWalker getzWalker() {
		return zWalker;
	}

	public void setzWalker(ZWalker zWalker) {
		this.zWalker = zWalker;
	}

	public ZMarker getzMarker() {
		return zMarker;
	}

	public void setzMarker(ZMarker zMarker) {
		this.zMarker = zMarker;
	}

	public ZStatusBar getzStatusBar() {
		return zStatusBar;
	}

	public void setzStatusBar(ZStatusBar zStatusBar) {
		this.zStatusBar = zStatusBar;
	}

	protected void fillContent() {

		JPanel backPanel = new JPanel();
		backPanel.setLayout(new BorderLayout());
		backPanel.setBorder(BorderFactory.createEtchedBorder());

		backPanel.add(zToolBar, BorderLayout.NORTH);

		JSplitPane parent = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
		JSplitPane son = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);

		son.setTopComponent(zWalker);
		son.setBottomComponent(zMarker);
		son.setDividerLocation(0.3);
		son.setOneTouchExpandable(true);
		son.setResizeWeight(1.0);

		parent.setLeftComponent(zNavigator);
		parent.setRightComponent(son);
		parent.setOneTouchExpandable(true);
		parent.setDividerLocation(200);
		parent.setResizeWeight(0);

		backPanel.add(parent, BorderLayout.CENTER);
		backPanel.add(zStatusBar, BorderLayout.SOUTH);
		getContentPane().add(backPanel);

	}

	private void configureLocation() {

		GraphicsEnvironment ge = GraphicsEnvironment
				.getLocalGraphicsEnvironment();
		Rectangle bounds = ge.getMaximumWindowBounds();

		Dimension d = new Dimension(bounds.width, bounds.height);
		setSize(d.width / 3 * 2, d.height / 3 * 2);
		toFront();
		Dimension c = getSize();
		int x = (d.width - c.width) / 2;
		int y = (d.height - c.height) / 2;
		setLocation(x, y);
	}
}
